<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-08-22
 * Time: 15:11
 */
namespace App\Http\Controllers\Mobile;
use App\Http\Controllers\Controller;
use App\Model\Mobile\MobilePlan;
use App\Tool\Error;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Validator;

class PlanTaskController extends Controller{
    /**
     * 移动端计划任务列表
     */
    public function plantasklist(Request $request)
    {
        $plan = new MobilePlan();
        $list = $plan->listPlan();
        if (!$list) {
            return $this->error(Error::NULL_DATA);
        }
        return $this->success('ok', $list);
    }

    /**
     * 修改计划任务
     */
    public function updateplantask(Request $request){
        $params = $request->all();
        $validator = Validator::make($params, [
            'hmp_id'   =>   'required',
            'hmp_sign_type'   => 'required',
            'hmp_status'   => 'required',
            'hmp_plan_time'   => 'required'
        ]);

        $params['hmp_update_time'] = time();
        if ($validator->fails()) {
            return $this->error(Error::PARAM_MISSING);
        }
        $plan = new MobilePlan();
        $res = $plan->updatePlan($params);

        if (!$res) {
            return $this->error(Error::EDIT_ERROR);
        }
        return $this->success('ok', '修改成功');

    }

    /**
     * 删除计划任务
     */
    public function delplantask(Request $request){

        $params = $request->all();
        $validator = Validator::make($params, [
            'hmp_sign_type'   => 'required',
          ]);


        if ($validator->fails()) {
            return $this->error(Error::PARAM_MISSING);
        }
        $plan = new MobilePlan();
        $res = $plan->delPlan($params);

        if (!$res) {
            return $this->error(Error::DEL_ERROR);
        }
        return $this->success('ok', '删除成功');
    }
}